/*
 * PreferencesGUI.java
 *
 * Created on July 29, 2007, 6:28 PM
 * 
 * @author Truben
 */

package no.truben.dbox.GUI.windows;

import no.truben.dbox.Main;
import no.truben.dbox.util.FileChooserFilter;
import no.truben.dbox.util.ThemeSupport;
import no.truben.dbox.util.HelperClass;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import no.truben.dbox.util.Constants;

public class Preferences extends javax.swing.JDialog {

    private int iconindex;
    
    /** Creates new form PreferencesGUI */
    public Preferences() {
        
        initComponents();

        txtDosBoxPath.setText(Main.pref.getDosBoxPath());
        chkKeepOpen.setSelected(Main.pref.isKeepOpen());
        chkFullscreen.setSelected(Main.pref.isFullScreen());
        chkNoConcole.setSelected(!Main.pref.isNoConcole());
        cmbKeyboard.setSelectedIndex(Main.pref.getKeyboardIndex());
        cmbIconSize.setSelectedIndex(Main.pref.getIconSizeIndex());

        chkCheckForUpdates.setSelected(Main.pref.isCheckForUpdates());

        fixListDisplayOptions();

        iconindex = cmbIconSize.getSelectedIndex();

        themeName.setText(Main.pref.getTheme());
        
        int columns = Main.pref.getNumerOfColumnsInGameList();
        if(columns >= 0 && columns <= cmbColumns.getItemCount())
            cmbColumns.setSelectedIndex(columns-1);

        centerScreen();
    }


    
    /**
     * Putter boksen midt paa skjermen
     */
    public void centerScreen() {
    	  Dimension dim = getToolkit().getScreenSize();
    	  Rectangle abounds = getBounds();
    	  setLocation((dim.width - abounds.width) / 2,
    	      (dim.height - abounds.height) / 2);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cmdConfirm = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel()
        {
            ImageIcon backImage = new javax.swing.ImageIcon(getClass().getResource(Constants.IMAGE_FOLDER + "bg.jpg"));
            Image image = backImage.getImage();
            int w = backImage.getIconWidth();

            public void paintComponent (Graphics g) {
                for(int i=0;i<100;i++)
                g.drawImage(image, w*i, 0, this);
                super.paintComponent(g);
            }
        }
        ;
        jLabel5 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        chkFullscreen = new javax.swing.JCheckBox();
        chkKeepOpen = new javax.swing.JCheckBox();
        cmbKeyboard = new javax.swing.JComboBox();
        cmdBrowse = new javax.swing.JButton();
        txtDosBoxPath = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        chkNoConcole = new javax.swing.JCheckBox();
        chkCheckForUpdates = new javax.swing.JCheckBox();
        jPanel3 = new javax.swing.JPanel();
        cmbIconSize = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        themeName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cmdBrowse1 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        cmbColumns = new javax.swing.JComboBox();
        cmbListDisplay = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Preferences");
        setModal(true);
        setResizable(false);

        cmdConfirm.setText("Close");
        cmdConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdConfirmActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setForeground(new java.awt.Color(255, 255, 255));
        jPanel1.setOpaque(false);

        jLabel5.setFont(new java.awt.Font("Lucida Grande", 2, 18));
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Preferences");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel5)
                .addContainerGap(477, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .add(jLabel5)
                .add(15, 15, 15))
        );

        jPanel2.setOpaque(false);

        chkFullscreen.setText("Play games in full screen (Press Alt+Enter in game to toggle)");
        chkFullscreen.setToolTipText("If you check this, your programs will run in full screen.\nYou can toggle by using the key combination Alt + Enter");
        chkFullscreen.setMargin(new java.awt.Insets(0, 0, 0, 0));

        chkKeepOpen.setText("Keep the DosBox window open (doesn't always work)");
        chkKeepOpen.setToolTipText("Determines if the DosBox window will be closed after the application\nyou currently are running has halted. This option will only have effect\non applications that you're opening after you have altered this preference.");
        chkKeepOpen.setMargin(new java.awt.Insets(0, 0, 0, 0));

        cmbKeyboard.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Belgium", "Brazil", "Canadian-French", "Czech Republic", "Denmark", "Finland", "France", "Germany", "Hungary", "Italy", "Latin America", "Netherlands", "Norway", "Poland", "Portugal", "Slovak Republic", "Spain", "Sweden", "Switzerland (French)", "Switzerland (German)", "United Kingdom", "United States", "United States (Dvorak)", "Yugoslavia (Serbo-Croatian)" }));
        cmbKeyboard.setToolTipText("Select your keyboard layout.\n\nNote that some games needs a specific\nkeyboard layout (often english).");
        cmbKeyboard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbKeyboardActionPerformed(evt);
            }
        });

        cmdBrowse.setIcon(new javax.swing.ImageIcon(getClass().getResource(Constants.IMAGE_FOLDER + "folder.png")));
        cmdBrowse.setToolTipText("Browse...");
        cmdBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdBrowseActionPerformed(evt);
            }
        });

        txtDosBoxPath.setToolTipText("The full path to the DosBox executable. On MacOs X this path has to point to the\nexecutable inside the app package. If you chose browse, D-Box will do this by\nitself to please and serve you!");
        txtDosBoxPath.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDosBoxPathActionPerformed(evt);
            }
        });

        jLabel2.setText("Keyboard Layout (Country or language):");

        jLabel1.setText("Path to DosBox");

        chkNoConcole.setText("Show DosBox concole");
        chkNoConcole.setToolTipText("Check this if you want to see a debug console.");
        chkNoConcole.setMargin(new java.awt.Insets(0, 0, 0, 0));
        chkNoConcole.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkNoConcoleActionPerformed(evt);
            }
        });

        chkCheckForUpdates.setText("Check for newer versions of D-Box at startup");
        chkCheckForUpdates.setToolTipText("Connect to D-Box servers and check for newer versions. No information about you is sent.");
        chkCheckForUpdates.setMargin(new java.awt.Insets(0, 0, 0, 0));

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                        .add(txtDosBoxPath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cmdBrowse))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 33, Short.MAX_VALUE)
                        .add(cmbKeyboard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jLabel1)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, chkKeepOpen, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
                    .add(chkCheckForUpdates, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
                    .add(chkFullscreen, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE)
                    .add(chkNoConcole, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(cmdBrowse)
                    .add(txtDosBoxPath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cmbKeyboard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 39, Short.MAX_VALUE)
                .add(chkCheckForUpdates, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(chkKeepOpen, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(chkFullscreen, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(chkNoConcole, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(20, 20, 20))
        );

        jTabbedPane1.addTab("General", jPanel2);

        jPanel3.setOpaque(false);

        cmbIconSize.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Small (16x16)", "Medium (22x22)", "Large (32x32)", "X-Large (48x48)", "Small Screenshot (160x100)", "Full Screenshot (320x200)" }));
        cmbIconSize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbIconSizeActionPerformed(evt);
            }
        });

        jLabel3.setText("Icon Size in Application List");

        themeName.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                themeNameCaretUpdate(evt);
            }
        });
        themeName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                themeNameActionPerformed(evt);
            }
        });

        jLabel4.setText("Theme Path:");

        cmdBrowse1.setIcon(new javax.swing.ImageIcon(getClass().getResource(Constants.IMAGE_FOLDER + "folder.png")));
        cmdBrowse1.setToolTipText("Browse...");
        cmdBrowse1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdBrowse1ActionPerformed(evt);
            }
        });

        jButton1.setText("Use Default Theme");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Theme Information");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel6.setText("Number of Columns in Application List");

        cmbColumns.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1 Column", "2 Columns", "3 Columns", "4 Columns", "5 Columns", "6 Columns", "7 Columns", "8 Columns" }));

        cmbListDisplay.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Image and Text", "Text", "Image" }));

        jLabel7.setText("Show Application in Applications List as");

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel4)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                        .add(themeName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cmdBrowse1))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton1)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton2)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel6)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 143, Short.MAX_VALUE)
                        .add(cmbColumns, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 107, Short.MAX_VALUE)
                        .add(cmbIconSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                        .add(jLabel7)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 107, Short.MAX_VALUE)
                        .add(cmbListDisplay, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel4)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(themeName)
                    .add(cmdBrowse1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jButton2)
                .add(26, 26, 26)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(cmbIconSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(cmbColumns, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cmbListDisplay, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel7))
                .add(14, 14, 14))
        );

        jTabbedPane1.addTab("Appearance", jPanel3);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE)
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(501, Short.MAX_VALUE)
                .add(cmdConfirm)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cmdConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(8, 8, 8))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-597)/2, (screenSize.height-441)/2, 597, 441);
    }// </editor-fold>//GEN-END:initComponents

private void cmdBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdBrowseActionPerformed
    String file = HelperClass.showFileChooser(this, "Select DosBox executable",
            new FileChooserFilter(FileChooserFilter.STARTS_WITH, new String[]{"dosbox"}, "DOSBox"), false);


    if(file != null) {
            if(file.endsWith("app"))
                    file+="/Contents/MacOS/DOSBox";
            txtDosBoxPath.setText(file);
    }
}//GEN-LAST:event_cmdBrowseActionPerformed

private void cmdConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdConfirmActionPerformed

    // Check if something has changed
    boolean theme   = !Main.pref.getTheme().equals(themeName.getText());
    boolean icons   = cmbIconSize.getSelectedIndex() != iconindex;
    boolean columns = Main.pref.getNumerOfColumnsInGameList() != cmbColumns.getSelectedIndex()+1;

    
    Main.pref.setDosBoxPath(txtDosBoxPath.getText());
    Main.pref.setKeepOpen(chkKeepOpen.isSelected());
    Main.pref.setFullScreen(chkFullscreen.isSelected());
    Main.pref.setNoConcole(!chkNoConcole.isSelected());
    Main.pref.setKeyboardCountry(cmbKeyboard.getSelectedItem().toString());
    Main.pref.setCheckForUpdates(chkCheckForUpdates.isSelected());

    switch(cmbListDisplay.getSelectedIndex()) {
        case 0:
            Main.pref.setShowIcons(true);
            Main.pref.setShowText(true);
            break;
        case 1:
            Main.pref.setShowIcons(false);
            Main.pref.setShowText(true);
            break;
        case 2:
            Main.pref.setShowIcons(true);
            Main.pref.setShowText(false);
            break;
    }


    Main.pref.setNumerOfColumnsInGameList(cmbColumns.getSelectedIndex()+1);
    

    if(cmbIconSize.getSelectedIndex() != -1)
        Main.pref.setIconSize(cmbIconSize.getSelectedItem().toString());

    
    Main.pref.setTheme(themeName.getText());
    this.setVisible(false);

    if(theme || icons || columns)
        restart();

}//GEN-LAST:event_cmdConfirmActionPerformed

private void restart() {
    try {
        Main.pref.writeConfig(Main.configFile);
        Main.n.setVisible(false);
        Main.n.dispose();
    } catch (IOException ex) {
        Logger.getLogger(Preferences.class.getName()).log(Level.SEVERE, null, ex);
    }
}

private void txtDosBoxPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDosBoxPathActionPerformed
    
}//GEN-LAST:event_txtDosBoxPathActionPerformed

private void cmbKeyboardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbKeyboardActionPerformed

}//GEN-LAST:event_cmbKeyboardActionPerformed

private void cmbIconSizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbIconSizeActionPerformed

}//GEN-LAST:event_cmbIconSizeActionPerformed

private void themeNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_themeNameActionPerformed

}//GEN-LAST:event_themeNameActionPerformed

private void cmdBrowse1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdBrowse1ActionPerformed
    String file = HelperClass.showFileChooser(this, "Select theme",
            new FileChooserFilter(FileChooserFilter.EXTENSIONS, new String[]{".dbt"}, "D-Box Themes"), false);


    if(file != null) {
        themeName.setText(file);
    }
}//GEN-LAST:event_cmdBrowse1ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    themeName.setText("");
}//GEN-LAST:event_jButton1ActionPerformed

private void themeNameCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_themeNameCaretUpdate
    themeNameActionPerformed(null);
}//GEN-LAST:event_themeNameCaretUpdate

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    ThemeSupport t;
    if(themeName.getText().equals(""))
        t = new ThemeSupport();
    else
        t = new ThemeSupport(new File(themeName.getText()));

    JOptionPane.showMessageDialog(this, t.toString(), t.getName(), JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_jButton2ActionPerformed

private void chkNoConcoleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkNoConcoleActionPerformed
}//GEN-LAST:event_chkNoConcoleActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox chkCheckForUpdates;
    private javax.swing.JCheckBox chkFullscreen;
    private javax.swing.JCheckBox chkKeepOpen;
    private javax.swing.JCheckBox chkNoConcole;
    private javax.swing.JComboBox cmbColumns;
    private javax.swing.JComboBox cmbIconSize;
    private javax.swing.JComboBox cmbKeyboard;
    private javax.swing.JComboBox cmbListDisplay;
    private javax.swing.JButton cmdBrowse;
    private javax.swing.JButton cmdBrowse1;
    private javax.swing.JButton cmdConfirm;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField themeName;
    private javax.swing.JTextField txtDosBoxPath;
    // End of variables declaration//GEN-END:variables

    @Override
    public void dispose() {
        cmdConfirmActionPerformed(null);
    }

    private void fixListDisplayOptions() {
        boolean text = Main.pref.isShowText();
        boolean image = Main.pref.isShowIcons();
        if(text && image)
            cmbListDisplay.setSelectedIndex(0);
        else if(text && !image)
            cmbListDisplay.setSelectedIndex(1);
        else if(!text && image)
            cmbListDisplay.setSelectedIndex(2);
        else
            cmbListDisplay.setSelectedIndex(-1);


    }

}
